<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 
            思路：首先根据横轴进行反转，再根据对称轴反转
            */
            var rotate = function (matrix) {
                let m = matrix.length
                let n = matrix[0].length
                let top = 0
                let bottom = m - 1
                while (top < bottom) {
                    ;[matrix[top], matrix[bottom]] = [matrix[bottom], matrix[top]]
                    top++
                    bottom--
                }
                //对称轴反转
                for (let i = 0; i < m; i++) {
                    for (let j = i; j < n; j++) {
                        ;[matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]]
                    }
                }
                return matrix
            }
        </script>
    </body>
</html>
